use bevy::{input::{gamepad::GamepadButton, keyboard::KeyCode, mouse::MouseButton}, prelude::Component, reflect::Reflect};
use leafwing_input_manager::{prelude::{ButtonlikeChord, InputMap, MouseScrollDirection}, Actionlike};

#[derive(Debug,Clone, Copy,Actionlike,Component,Hash,PartialEq, Eq,Reflect)]
pub enum Action {
    MoveUp,
    MoveDown,
    MoveRight,
    MoveLeft,

    Undo,
    Redo,

    ResetLevel,
    NextLevel,
    PreviousLevel,
    NextUnsolvedLevel,
    PreviousUnsolvedLevel,

    ZoomIn,
    ZoomOut,


    ToggleInstantMove,
    ToggleAutomaticSolution,
    ToggleFullscreen,

    ImportLevelFromCliboard,
    ExportLevelToCliboard,
    
}

pub fn default_input_map() -> InputMap<Action> {
    let mouse_input_map = InputMap::default()
        .with_multiple([
            (Action::Undo,MouseButton::Other(1)),
            (Action::Redo,MouseButton::Other(2)),
        ])
        .with_multiple([
            (Action::ZoomOut,MouseScrollDirection::DOWN),
            (Action::ZoomIn,MouseScrollDirection::UP),
        ]);

    let keyboard_input_map = InputMap::default()
            .with_multiple([
                (Action::MoveUp,KeyCode::KeyW),
            ])
            .with_multiple([
                (Action::Undo,ButtonlikeChord::new([KeyCode::ControlLeft,KeyCode::KeyZ])),
            ]);
    
    let gamepad_input_map = InputMap::default()
            .with_multiple([
                (Action::MoveUp,GamepadButton::DPadUp),
            ]);

    InputMap::default()
        .merge(&mouse_input_map)
        .merge(&keyboard_input_map)
        .merge(&gamepad_input_map)
        .clone()
}